package com.rtu.service.impl;

import com.rtu.dao.IRtuImageDao;
import com.rtu.domain.TbImage;
import com.rtu.dto.InsertOrUpImageDto;
import com.rtu.dto.QueryImageReqDto;
import com.rtu.dto.QueryImageRespDto;
import com.rtu.service.IImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by jiafeilu on 2018/5/7.
 */
@Service
public class ImageServiceImpl implements IImageService {
    @Autowired
    private IRtuImageDao imageDao;

    @Override
    public Boolean insertOrUpdate(InsertOrUpImageDto dto) {
        QueryImageReqDto req = new QueryImageReqDto();
        req.setAreaId(dto.getAreaId());
        req.setCh(dto.getCh());
        QueryImageRespDto resp = imageDao.select(req);

        TbImage image = new TbImage();
        image.setAreaId(dto.getAreaId());
        image.setCh(dto.getCh());
        image.setImageUrl(dto.getImageUrl());
        image.setDelFlag(0);
        if (resp == null) {
            imageDao.insert(image);
        } else {
            imageDao.update(image);
        }
        return true;
    }

    @Override
    public QueryImageRespDto query(QueryImageReqDto dto) {
        return imageDao.select(dto);
    }
}
